<extend name="Public/base" />

<block name="style">
    <link rel="stylesheet" type="text/css" href="__STATIC__/plugins/bootstrap-fileupload/bootstrap-fileupload.css" />
    <link rel="stylesheet" type="text/css" href="__STATIC__/plugins/bootstrap-datepicker/css/datepicker.css" />
    <link rel="stylesheet" type="text/css" href="__STATIC__/plugins/bootstrap-datetimepicker/css/datetimepicker.css" />
</block>


<block name="body">

        <!-- 表单 -->

<div class="row">
    <div class="col-md-12">
        
        <div class="tabbable tabbable-custom boxless">
        <form id="form" action="{:U('edit?name='.trim($_GET['name']))}" method="POST" class="form-1">
        <script> var _file = []; _file['picture'] = [];_file['file'] = [];</script>

            <div class="tab-content">
                <div class="portlet box red">
                    <div class="portlet-title">
                        <div class="caption"><i class="fa fa-reorder"></i> 编辑 [{$model['title']}] </div>
                        <div class="tools">
                            <a href="javascript:;" class="collapse"></a>
                            <a href="#portlet-config" data-toggle="modal" class="config"></a>
                            <a href="javascript:;" class="reload"></a>
                            <a href="javascript:;" class="remove"></a>
                        </div>
                    </div>
                    <div class="portlet-body form">
                        <!-- BEGIN FORM-->
                        <div class="form-body">
                        <volist name="fields" id="field">
                        <if condition="$field['is_show'] == 1 || $field['is_show'] == 2">
                            <div class="form-group">
                                <label>{$field['title']}<span class="check-tips"><notempty name="field['remark']">（{$field['remark']}）</notempty></span></label>

                                <switch name="field.type">
                                        <case value="num">
                                            <input type="text" class="form-control input-medium" name="{$field.name}" value="{$data[$field['name']]}">
                                        </case>
                                        <case value="string">
                                            <input type="text" class="form-control input-xlarge" name="{$field.name}" value="{$data[$field['name']]}">
                                        </case>
                                        <case value="textarea">
                                            <textarea class="form-control input-xlarge" rows="3"  name="{$field.name}" >{$data[$field['name']]}</textarea>

                                        </case>
                                        <case value="datetime">
                                            <div class="input-group input-large date form_datetime">                             
                                                <span class="input-group-btn">
                                                <button class="btn default date-set" type="button"><i class="fa fa-calendar"></i></button>
                                                </span>          
                                                <input type="text" size="16" name="{$field.name}" value="{$data[$field['name']]|time_format}" readonly class="form-control">
                                            </div>
                                        </case>
                                        <case value="bool">
                                            <select class="form-control input-medium" name="{$field.name}">
                                                <volist name=":parse_field_attr($field['extra'])" id="vo">
                                                    <option value="{$key}" <eq name="data[$field['name']]" value="$key">selected</eq>>{$vo}</option>
                                                </volist>
                                            </select>
                                        </case>
                                        <case value="select">
                                            <select class="form-control input-medium" name="{$field.name}">
                                                <volist name=":parse_field_attr($field['extra'])" id="vo">
                                                    <option value="{$key}" <eq name="data[$field['name']]" value="$key">selected</eq>>{$vo}</option>
                                                </volist>
                                            </select>
                                        </case>
                                        <case value="radio">
                                            <div class="radio-list">
                                            <volist name=":parse_field_attr($field['extra'])" id="vo">
                                                <label class="radio-inline">
                                                <input type="radio" name="{$field.name}" <eq name="data[$field['name']]" value="$key">checked</eq>  value="{$key}"> {$vo}
                                                </label>
                                            </volist>
                                            </div>
                                        </case>

                                        <case value="checkbox">
                                            <div class="checkbox-list">
                                            <volist name=":parse_field_attr($field['extra'])" id="vo">
                                                <label class="checkbox-inline">
                                                <input type="checkbox" value="{$key}" name="{$field.name}[]" <eq name="data[$field['name']]" value="$key">checked</eq>>{$vo}
                                                </label>
                                            </volist>
                                            </div>
                                        </case>
                                        <case value="editor">
                                            <textarea name="{$field.name}" rows="20">{$data[$field['name']]}</textarea>
                                            {:hook('adminArticleEdit', array('name'=>$field['name'],'value'=>$data[$field['name']]))}
                                        </case>
                                        <case value="picture">
                                            <script> _file['picture'].push("{$field.name}")</script>
                                            <div class="fileupload fileupload-new" data-provides="fileupload">
                                                <div class="fileupload-new thumbnail" >
                                                <empty name="data[$field['name']]">
                                                    <img id="field_pic_{$field.name}" src="__STATIC__/img/noimage.gif" alt="" />
                                                <else />
                                                    <img id="field_pic_{$field.name}" src="__ROOT__{$data[$field['name']]|get_cover='path'}" alt="" />
                                                </empty>
                                                </div>
                                                <div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 200px; max-height: 150px; line-height: 20px;"></div>
                                                <div>
                                                    <input type="file" class="default"   id="{$field.name}"  />
                                                    <input type="hidden"   name="{$field.name}" id="field_{$field.name}" value="{$data[$field['name']]}" />
                                                    
                                                </div>
                                            </div>
                                        </case>
                                        <case value="file">
                                            <script> _file['file'].push("{$field.name}")</script>
                                            <div class="fileupload fileupload-new" data-provides="fileupload"  data-filed="{$field.name}">
                                                <div class="input-group">
                                                    <span class="input-group-btn">
                                                        <span class="uneditable-input">
                                                            <i class="fa fa-file"></i> 
                                                            <span class="fileupload-preview">{$data[$field['name']]|get_table_field=###,'id','name','File'}</span>
                                                        </span>
                                                    </span>
                                                    <span class="btn-file">
                                                        <input type="file" class="default"  id="{$field.name}" />
                                                        <input type="hidden" name="{$field.name}" id="field_{$field.name}" value="{:think_encrypt(json_encode(get_table_field($data[$field['name']],'id','','File')))}"/>
                                                    </span>
                                                    <a href="#" class="btn red fileupload-exists" data-dismiss="fileupload"><i class="fa fa-trash-o"></i> 删除</a>
                                                </div>
                                            </div>
                                        </case>
                                        <default/>
                                        <input type="text" class="form-control"  name="{$field.name}" value="{$data[$field['name']]}">
                                </switch>
                            </div>
                        </if>
                        </volist>
                        <input type="hidden" name="id" value="{$data.id|default=0}">
                        </div>
                        
                        
                        <div class="form-actions fluid ">
                            <div class="col-md-offset-3 col-md-9">
                                <button class="btn green submit-btn ajax-post" id="submit" type="submit"  target-form="form-1">确 定</button>
                                <a class="btn default btn-return" href="{$Think.cookie.__forward__}">返 回</a>                         
                            </div>
                        </div>
                        <!-- END FORM--> 
                        </div>
                    </div>
                </div>
            </div>

        </form>
        </div>
    </div>
</div>


</block>

<block name="script">
    <!-- BEGIN PAGE LEVEL PLUGINS -->
    <script type="text/javascript" src="__STATIC__/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
    <script type="text/javascript" src="__STATIC__/plugins/bootstrap-datepicker/js/locales/bootstrap-datepicker.zh-CN.js"></script>
    <script type="text/javascript" src="__STATIC__/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
    <script type="text/javascript" src="__STATIC__/plugins/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
    <!-- END PAGE LEVEL PLUGINS -->
    <!-- BEGIN PAGE LEVEL SCRIPTS -->
    <script src="__STATIC__/scripts/app.js"></script>
    <script src="__STATIC__/scripts/form-components.js"></script> 
    <script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js?t={:rand(0,9999)}"></script>
    <!-- END PAGE LEVEL SCRIPTS -->
    <script>
    jQuery(document).ready(function() {       
        // initiate layout and plugins
        App.init();
        FormComponents.init();
        
        highlight_subnav('{:U('Model/index')}');

        _file['picture'].forEach(function(i){
            $("#"+i).uploadify({
                "height"          : 34,
                "swf"             : "__STATIC__/uploadify/uploadify.swf",
                "fileObjName"     : "download",
                "buttonText"      : "上传图片",
                "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
                "width"           : 80,
                'removeTimeout'   : 1,
                'fileTypeExts'    : '*.jpg; *.png; *.gif;',
                "onUploadSuccess" : function(file, data){
                    var data = $.parseJSON(data);
                    var src = '';
                    if(data.status){
                        $("#field_"+i).val(data.id);
                        src = data.url || '__ROOT__' + data.path
                        $("#field_pic_"+i).attr({"src":src}).parent().css({"width":'',"height":''});
                    } else {
                        updateAlert(data.info);
                        setTimeout(function(){
                            $('#top-alert').find('button').click();
                            $(that).removeClass('disabled').prop('disabled',false);
                        },1500);
                    }
                },
                'onFallback' : function() {
                    alert('未检测到兼容版本的Flash.');
                }
            });
        })
        
        _file['file'].forEach(function(i){
            $("#"+i).uploadify({
                "height"          : 34,
                "swf"             : "__STATIC__/uploadify/uploadify.swf",
                "fileObjName"     : "download",
                "buttonText"      : "上传附件",
                "uploader"        : "{:U('File/uploadCOA',array('session_id'=>session_id()))}",
                "width"           : 120,
                'removeTimeout'   : 1,
                "onUploadSuccess" : function(file, data){
                    var data = $.parseJSON(data);
                    
                    if(data.status){
                        var name = i;
                        $("input[name="+name+"]").val(data.data);
                        $('div[data-filed='+name+'] .uneditable-input').find('.fileupload-preview').html(data.info);
                        $('div[data-filed='+name+'] .uneditable-input').find('i').removeClass('fileupload-exists');
                    } else {
                        updateAlert(data.info);
                        setTimeout(function(){
                            $('#top-alert').find('button').click();
                        },1500);
                    }
                },
                'onFallback' : function() {
                    alert('未检测到兼容版本的Flash.');
                }
            });
        })
        

    });
    </script>
</block>